package com.catena.web.websocket;

import com.catena.core.node.CatenaNode;
import com.catena.mock.param.MockBaseParam;
import com.catena.response.ApiUpdateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.websocket.EncodeException;
import java.io.IOException;

/**
 * Created by hx-pc on 16-11-1.
 */
public class NoticeNode extends CatenaNode {

    private static Logger LOGGER = LoggerFactory.getLogger(NoticeMessage.class);

    public void sendApiUpdateMessage(MockBaseParam mockBaseParam) {
        ApiUpdateResponse response = new ApiUpdateResponse();
        response.setProject(mockBaseParam.acceptServletRequest().getHeader("project"));
        response.setMethod(mockBaseParam.getHttpRequestMethod().name());
        response.setApi(mockBaseParam.getApiValue());
        response.setKey(mockBaseParam.getKey());
        new Thread(() -> {
            LOGGER.info("开始发送数据");
            try {
                getBean(NoticeMessage.class).sendApiUpdateMessageAll(response);
            } catch (IOException | EncodeException e) {
                LOGGER.info("api数据修改消息推送失败:{}", e);
            }
        }).start();
    }
}
